package com.showdoc.controller;

import com.showdoc.mapper.PageMapper;
import com.showdoc.pojo.Page;
import com.showdoc.utils.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("page")
@EnableAutoConfiguration
public class PageController {

    @Autowired
    private PageMapper pageMapper;

    //查询单页数据
//    @GetMapping("/info")
//    public R getPageInfo(@Param("pageId") Long pageId)
//    {
//        Page singlePage = pageMapper.findByPageId(pageId);
//        if(singlePage == null){
//            return R.error("请求失败。请重试...");
//        }
//        return R.success(singlePage);
//    }

    //根据项目ID查询Page数据
    @GetMapping("/info")
    public R getPageInfo(@Param("itemId") Long itemId)
    {
        Page page = pageMapper.findByItemID(itemId);
        if(page == null){
            return R.error("请求失败。请重试...");
        }
        return R.success(page);
    }
}
